package com.global.college.ui.presenter;

import android.content.Context;

import com.google.gson.Gson;
import com.global.college.api.ProgressSubscriber;
import com.global.college.api.AuthURLs;
import com.global.college.base.BasePresenter;
import com.global.college.data.WeChatTokenBean;
import com.global.college.ui.bean.LoginModel;
import com.global.college.ui.bean.WechatLoginModel;
import com.global.college.ui.bean.WechatUserModel;
import com.global.college.ui.interfaces.ILoginView;


import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * 登录
 */
public class LoginPresenter extends BasePresenter {

    private ILoginView mILoginView;

    public LoginPresenter(Context context) {
        super(context);
    }

    public void setLoginView(ILoginView loginView){
        mILoginView = loginView;
    }

    /**
     * 4.登录
     * username	     用户名
     * password	    密码
     * code	        验证码
     * source	    来源
     */
    public void login(String username, String password, String code){
        mAuthRequestClient.login(username,password,code).subscribe(new ProgressSubscriber<LoginModel>(mContext,true) {
            @Override
            public void onNext(LoginModel loginModel) {
                if(null != mILoginView){
                    mILoginView.onLoginSuccess(loginModel);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mILoginView.onLoginFail(e.getMessage());
            }
        });
    }

    /**
     * 获取验证码
     * @param
     */
    public void getSmsCode(String phone){
        mAuthRequestClient.getSmsCode(phone).subscribe(new ProgressSubscriber<Object>(mContext,true) {
            @Override
            public void onNext(Object smsModel) {
                if(null != mILoginView){
                    mILoginView.onGetSmsCodeSuccess(smsModel);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mILoginView.onGetSmsCodeFail(e.getMessage());
            }
        });
    }

}
